package com.hn.vue.controller;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.DefaultRedirectStrategy;
import org.springframework.security.web.RedirectStrategy;
import org.springframework.security.web.util.RedirectUrlBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * hanni
 * 2019/3/6 0006
 * 11:56
 */
@RestController
@RequestMapping
public class RestLoginController {

    //重定向
    private RedirectStrategy strategy = new DefaultRedirectStrategy();

    @GetMapping("/login")
    public void login(HttpServletRequest request,HttpServletResponse response) throws Exception {

        strategy.sendRedirect(request,response,"/login.html");
    }


    @GetMapping("/info")
    public String userinfo(){
        return SecurityContextHolder.getContext().getAuthentication().getDetails().toString();
    }
}
